package com.woniuxy.driverschool.controller;

import com.woniuxy.driverschool.entity.Car;
import com.woniuxy.driverschool.entity.ResponseResult;
import com.woniuxy.driverschool.service.CarService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/car")
public class CarController {
    @Resource
    private CarService carService;
    @RequestMapping("/all")
    public ResponseResult<List<Car>> all(){
      ResponseResult<List<Car>>  responseResult = new ResponseResult<>();
      responseResult.setData(carService.all());
      responseResult.setMessage("获取全部车辆信息成功");
      responseResult.setState(200);
      return responseResult;
    };
    @PostMapping("/findByOptions")
    public ResponseResult<List<Car>>  findByOptions(@RequestBody Car car){
        ResponseResult<List<Car>> responseResult = new ResponseResult<>();
        responseResult.setData(carService.findCarByOptions(car));
        responseResult.setMessage("获取车辆信息成功");
        responseResult.setState(200);
        System.out.println(responseResult.getData());
        return responseResult;
    }
    @PostMapping("/add")
    public ResponseResult<Integer> add(@RequestBody Car car){
        ResponseResult<Integer> responseResult = new ResponseResult<>();
        carService.add(car);
        responseResult.setMessage("添加汽车成功");
        responseResult.setState(200);
        return responseResult;
    }

}
